<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>登录</title>
		<!-- 样 式 文 件 -->
		<link rel="stylesheet" href="/static/admin/component/pear/css/pear.css" />
		<link rel="stylesheet" href="/static/admin/css/other/login.css" />
	</head>
    <!-- 代 码 结 构 -->
	<body style="background-size: cover;">
		<form class="layui-form" action="">
			{:token()}
			<div class="layui-form-item">
				<img class="logo" src="/static/admin/images/logo.png" />
				<div class="title">GAdmin</div>
				<div class="desc">
					以 有 限的 资 源 获 取 最 大 限 度 的 增 长
				</div>
			</div>
			<div class="layui-form-item">
				<input name="username" placeholder="账 户 :  " lay-verify="required" hover class="layui-input"  />
			</div>
			<div class="layui-form-item">
				<input name="password" type="password" placeholder="密 码 :  " lay-verify="required" hover class="layui-input"  />
			</div>
			<!-- <div class="layui-form-item">
				<input placeholder="验证码 : "  hover  lay-verify="required" class="code layui-input layui-input-inline"  />
				<img src="/static/admin/images/captcha.gif" class="codeImage" />
			</div>
			
			<div class="layui-form-item">
				<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
			</div> -->
			<div class="layui-form-item">
				<button type="submit" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
					登 入
				</button>
			</div>
		</form>
		<!-- 资 源 引 入 -->
		{include file="inc/pear" /}
		<script>
			layui.use(['jquery','form', 'button', 'popup','layer'], function() {
				var $ = layui.jquery,form = layui.form;
				var button = layui.button;
				var popup = layui.popup;
				
                // 登 录 提 交
				form.on('submit(login)', function(data) {
					var that = $(this), _form = that.parents('form'),
						account = $('input[name="username"]').val(),
						pwd = $('input[name="password"]').val(),
						token = $('input[name="__token__"]').val();

					var index = layer.msg('数据提交中...',{time:500000});
					that.prop('disabled', true);
					/// 登录
					$.ajax({
						type: "POST",
						url: _form.attr('action'),
						data: {'username': account, 'password': pwd, '__token__' : token},
						success: function(res) {
							if (res.token) {
								$('input[name="__token__"]').val(res.token);
							}

							if(res.code == 0){
								layer.msg(res.msg);
								that.prop('disabled', false);
								return false;
							} 

							/// 动画
							button.load({
								elem: '.login',
								time: 500,
								done: function() {
									popup.success("登录成功", function() {
										location.href = res.url;
									});
								}
							})

						}
					});
					return false;
				});
			})
		</script>
	</body>
</html>
